<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\SchoolRoles;
use Illuminate\Support\Facades\Auth;

class UserController extends Controller
{
    public function info()
    {
        $user = Auth::user();
        $roleId = $user->role()->min('id');
        $school = $user->school()->get();
        $roleId = $roleId ?: SchoolRoles::VISIT_ROLE;

        $data = [
            'uid' => $user->id,
            'nickname' => $user->name,
            'email' => $user->email,
            'role_id' => $roleId,
            'school' => $school,
        ];

        return success($data);
    }
}